﻿@{
    Layout = "";
}
<style>
    .ngdialog-content {
        width: 333px !important;
    }
    .appmsg_col {
    display: inline-block;
    vertical-align: top;
    width: 32%;
    text-align: left;
    font-size: 14px;
    letter-spacing: normal;
}
    .appmsg {
    position: relative;
    overflow: hidden;
    margin-bottom: 20px;
    border: 1px solid #e7e7eb;
    background-color: #fff;
    color: #666;
}
    .appmsg_col {
    display: inline-block;
    vertical-align: top;
    width: 32%;
    text-align: left;
    font-size: 14px;
    letter-spacing: normal;
}
    .multi .appmsg_content {
    padding: 0;
}
    .appmsg_content {
    position: relative;
}
    .has_first_cover .cover_appmsg_item {
    margin: 12px 14px 12px;
}
.cover_appmsg_item {
    position: relative;
    margin: 12px 14px;
}
.has_first_cover .cover_appmsg_item .appmsg_title {
    font-size: 14px;
    padding-top: 0;
    line-height: 28px;
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0,0,0,0.6)!important;
    filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#99000000',endcolorstr = '#99000000');
}
.appmsg_title {
    font-weight: 400;
    font-style: normal;
    font-size: 14px;
    line-height: 1.6;
    max-height: 3.2;
    overflow: hidden;
    word-wrap: break-word;
    word-break: break-all;
    color: #222;
}
.appmsg_thumb_wrp {
    height: 160px;
    overflow: hidden;
    background-repeat: no-repeat;
    background-position: center center;
    background-size: cover;
}
.cover_appmsg_item .edit_mask.preview_mask {
    left: -14px;
    right: -14px;
    top: -12px;
    bottom: -12px;
}
.edit_mask.preview_mask {
    display: none;
}
.edit_mask {
    font-size: 0;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.6)!important;
    filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#99000000',endcolorstr = '#99000000');
    color: #fff;
    z-index: 1;
    text-align: center;
    padding: 14px;
}
.edit_mask_content {
    display: inline-block;
    vertical-align: middle;
    font-size: 14px;
}
.vm_box {
    display: inline-block;
    height: 100%;
    vertical-align: middle;
}
</style>
<h3>图文素材</h3>
<div class="panel panel-default" ng-controller="ImageTextController" ng-class="{ 'whirl standard': isLoading }">
    <div class="panel-heading">
        <div class="form-inline ng-pristine ng-valid">
            <div class="form-group">
                <input placeholder="关键字" class="form-control" type="text" ng-model="Keywords">
                <button type="submit" class="btn btn-labeled btn-primary" ng-click="tableParams.$params.page = 1;tableParams.reload()">
                    <span class="btn-label">
                        <em class="fa fa-search"></em>
                    </span>搜索
                </button>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <button type="button" class="btn btn-labeled btn-success" ng-click="editBasicInfo(0)">
                    <span class="btn-label">
                        <i class="fa fa-plus"></i>
                    </span>添加图文素材
                </button>
            </div>
        </div>
    </div>

    <div class="panel-body">
        <div class="table-responsive">
            <table ng-table="tableParams" class="table table-striped table-bproducted table-hover">
                <tbody>
                    <tr ng-repeat="dataInfoManage in $data">
                        <td data-title="'文章标题'" class="text-center" sortable="'Title'">{{dataInfoManage.Title}}</td>
                        <td data-title="'创建时间'" class="text-center" sortable="'AddTime'">{{dataInfoManage.AddTime}}</td>
                        <td data-title="''" nowrap="nowrap" class="text-center">

                            <button type="button" ng-click="Review(dataInfoManage.GroupId)" class="btn btn-sm btn-success" title="预览">
                                <em class="fa fa-toggle-right"></em>
                            </button>

                            <button type="button" ng-click="editBasicInfo(dataInfoManage.GroupId)" class="btn btn-sm btn-info" title="编辑">
                                <em class="fa fa-edit"></em>
                            </button>
                            <button ng-click="removeInfo(dataInfoManage.GroupId)" title="删除" class="btn btn-sm btn-danger">
                                <em class="fa fa-trash"></em>
                            </button>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
<script type="text/ng-template" id="passConfirmDialog">
    <div class="ngdialog-message text-center">
        <h3>确定要删除吗?</h3>
        <p>删除后，设置的相关自动回复内容将不再回复该图文素材。删除后，不可恢复，是否确认删除？</p>
        <br />
        <button type="button" ng-click="confirm()" class="btn btn-primary mr">确认</button>
        <button type="button" ng-click="closeThisDialog('button')" class="btn btn-default">取消</button>
    </div>
</script>

<script type="text/ng-template" id="reviewConfirmDialog">
    <div>
        <div class="appmsg_col" style="width:100%">
            <div class="appmsg multi has_first_cover" ng-if="ResponseData.ImageTexts.length>1">
                <div class="appmsg_content">

                    <div ng-repeat="imageText in ResponseData.ImageTexts">



                        <div class="cover_appmsg_item" ng-if="imageText.IsMain">
                            <h4 class="appmsg_title js_title">

                                <a href="" target="_blank" data-msgid="100000040" data-idx="0">{{imageText.Title}}</a>

                            </h4>

                            <div class="appmsg_thumb_wrp" style="background-image:url('{{imageText.PicUrl}}')">
                            </div>

                            <a href="{{imageText.Url}}" target="_blank" class="edit_mask preview_mask js_preview" data-msgid="100000078" data-idx="0">
                                <div class="edit_mask_content">
                                    <p class="">
                                        预览文章
                                    </p>
                                </div>
                                <span class="vm_box"></span>
                            </a>

                        </div>

                        <div class="appmsg_item has_cover" ng-if="!imageText.IsMain">
                            <div class="appmsg_thumb_wrp" style="background-image:url('{{imageText.PicUrl}}')">
                            </div>
                            <h4 class="appmsg_title js_title">
                                <a href="" target="_blank" data-msgid="100000040" data-idx="1">{{imageText.Title}}</a>
                            </h4>
                            <a href="{{imageText.Url}}" target="_blank" class="edit_mask preview_mask js_preview" data-msgid="100000078" data-idx="0">
                                <div class="edit_mask_content">
                                    <p class="">
                                        预览文章
                                    </p>
                                </div>
                                <span class="vm_box"></span>
                            </a>

                        </div>
                    </div>




                </div>





            </div>

            <div class="js_appmsgitem" ng-if="ResponseData.ImageTexts.length==1">
                <div class="appmsg single has_first_cover" data-id="100000026" data-fileid="100000024" data-completed="1">
                    <div class="appmsg_content">


                        <div class="appmsg_item">
                            <h4 class="appmsg_title js_title">

                                <a href="" target="_blank" data-msgid="100000078" data-idx="0">{{ResponseData.ImageTexts[0].Title}}</a>
                            </h4>
                            <div class="appmsg_thumb_wrp" style="background-image:url('{{ResponseData.ImageTexts[0].PicUrl}}')">
                            </div>

                            <p class="appmsg_desc">{{ResponseData.ImageTexts[0].Description}}</p>

                            <a href="{{ResponseData.ImageTexts[0].Url}}" target="_blank" class="edit_mask preview_mask js_preview" data-msgid="100000078" data-idx="0">
                                <div class="edit_mask_content">
                                    <p class="">
                                        预览文章
                                    </p>
                                </div>
                                <span class="vm_box"></span>
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>


    @*<button type="button" ng-click="confirm()" class="btn btn-primary mr">确认</button>
        <button type="button" ng-click="closeThisDialog('button')" class="btn btn-default">取消</button>*@

</script>
<script type="text/javascript">
    App.controller('ImageTextController', [
        '$scope', '$resource', '$state', '$route', 'ngDialog', '$http', 'ngTableParams', 'ngTableDataService', 'Notify',
        function ($scope, $resource, $state, $route, ngDialog, $http, ngTableParams, ngTableDataService, Notify) {
            'use strict';
            $scope.isLoading = true;
            $scope.tableParams = new ngTableParams({
                page: 1,
                count: 10,
                sorting: {
                    Id: 'desc'     // 初始化排序
                }
            }, {
                getData: function ($defer, params) {
                    $scope.isLoading = true;
                    var requestParams = {
                        Skip: (params.page() - 1) * params.count(),
                        Take: params.count(),
                        Keywords: $scope.Keywords
                    };
                    $http.post('/WxSet/ImageTextManage', ngTableDataService.getServerSideParams(params.orderBy().toString(), params, requestParams))
                        .success(function (data, status) {
                            params.total(data.Total);
                            $defer.resolve(data.Results);
                            $scope.isLoading = false;
                        });
                }
            });

            $scope.ResponseData = {};
            //跳转更新页面
            $scope.editBasicInfo = function (groupid) {
                $state.go('app.imagetextdetail', { "groupid": groupid });
            }

            $scope.Review = function (groupid) {


                $http.post("/WxSet/GetByGroupid", { GroupId: groupid }).success(function (data) {
                    console.log(data);
                    $scope.ResponseData.ImageTexts = data;

                    //  console.log($scope.ImageTexts)
                    ngDialog.openConfirm({
                        template: 'reviewConfirmDialog',
                        className: 'ngdialog-theme-default',
                        scope: $scope
                    }).then(function (value) {
                        //  console.log(value);
                        //$http.post("/mallimagetext/deletebygroupid", { GroupId: groupid }).then(function (returnData) {
                        //    if (returnData.data.IsSuccess) {
                        //        $scope.tableParams.reload();
                        //        Notify.alert('操作成功!', { status: 'success', timeout: 1000 });
                        //    } else {
                        //        Notify.alert(returnData.data.Message, { status: 'warning', timeout: 1000 });
                        //    }
                        //});
                    }, function (reason) {
                    }
             );

                })


            }

            //删除
            $scope.removeInfo = function (groupid) {
                ngDialog.openConfirm({
                    template: 'passConfirmDialog',
                    className: 'ngdialog-theme-default'
                }).then(function (value) {
                    $http.post("/WxSet/DeleteByGroupid", { GroupId: groupid }).then(function (returnData) {
                        if (returnData.data.isSuccess) {
                            $scope.tableParams.reload();
                            Notify.alert('操作成功!', { status: 'success', timeout: 1000 });
                        } else {
                            Notify.alert(returnData.data.msg, { status: 'warning', timeout: 1000 });
                        }
                    });
                }, function (reason) {
                }
                );
            }

        }]);
</script>